#include <iostream>

using std::cout;
using std::endl;

//i^2 = -1

class Complex
{
public:
    Complex(double dreal = 0.0, double dimag = 0.0)
    : _dreal(dreal)
    , _dimag(dimag)
    {
        cout << "Complex(double = 0.0, double = 0.0)" << endl;
    }

    void print() const
    {
        if((0 == _dreal) && (0 == _dimag))
        {
            cout << 0 << endl;
        }
        else if(0 == _dreal)
        {
            cout << _dimag << "i" << endl;
        }
        else
        {
            cout << _dreal;
            if(_dimag > 0)
            {
                cout << " + " << _dimag << "i" << endl;
            }
            else if(0 == _dimag)
            {
                cout << endl;
            }
            else
            {
                cout << " - " << (-1) *_dimag << "i" << endl;
            }
        }
    }

    ~Complex()
    {
        cout << "~Complex()" << endl;
    }
private:
    double _dreal;
    double _dimag;
};

void test()
{
    Complex com1(2, 3);
    cout << "com1 = ";
    com1.print();

    cout << endl;
    Complex com2(2, 0);
    cout << "com2 = ";
    com2.print();

    cout << endl;
    Complex com3(2, -3);
    cout << "com3 = ";
    com3.print();

    cout <<endl;
    Complex com4(-2, 3);
    cout << "com4 = ";
    com4.print();

    cout << endl;
    Complex com5(-2, 0);
    cout << "com5 = ";
    com5.print();

    cout << endl;
    Complex com6(-2, -3);
    cout << "com6 = ";
    com6.print();

    cout << endl;
    Complex com7(0, 3);
    cout << "com7 = ";
    com7.print();

    cout << endl;
    Complex com8(0, 0);
    cout << "com8 = ";
    com8.print();

    cout << endl;
    Complex com9(0, -3);
    cout << "com9 = ";
    com9.print();
}

int main(int argc, char *argv[])
{
    test();
    return 0;
}

